Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@dagrejs/graphlib
Advanced tools
@dagrejs/graphlib is a JavaScript library for creating and manipulating directed graphs. It provides a flexible and efficient way to work with graph data structures, including adding and removing nodes and edges, traversing the graph, and performing various graph algorithms.
Creating a Graph
This feature allows you to create a new graph, add nodes, and add edges between nodes. The code sample demonstrates creating a graph, adding two nodes 'a' and 'b', and creating an edge from 'a' to 'b'.
const graphlib = require('@dagrejs/graphlib');
const Graph = graphlib.Graph;
const g = new Graph();
g.setNode('a');
g.setNode('b');
g.setEdge('a', 'b');
console.log(g.nodes()); // ['a', 'b']
console.log(g.edges()); // [{ v: 'a', w: 'b' }]
Graph Traversal
This feature allows you to perform depth-first search (DFS) traversal on the graph. The code sample demonstrates creating a graph with three nodes and two edges, and then performing DFS starting from node 'a'.
const graphlib = require('@dagrejs/graphlib');
const Graph = graphlib.Graph;
const g = new Graph();
g.setNode('a');
g.setNode('b');
g.setNode('c');
g.setEdge('a', 'b');
g.setEdge('b', 'c');
const dfs = graphlib.alg.dfs(g, ['a']);
console.log(dfs); // [{ v: 'a' }, { v: 'b' }, { v: 'c' }]
Finding Shortest Path
This feature allows you to find the shortest path in the graph using Dijkstra's algorithm. The code sample demonstrates creating a graph with three nodes and three weighted edges, and then finding the shortest path from node 'a' to all other nodes.
const graphlib = require('@dagrejs/graphlib');
const Graph = graphlib.Graph;
const g = new Graph();
g.setNode('a');
g.setNode('b');
g.setNode('c');
g.setEdge('a', 'b', { weight: 1 });
g.setEdge('b', 'c', { weight: 2 });
g.setEdge('a', 'c', { weight: 4 });
const dijkstra = graphlib.alg.dijkstra(g, 'a');
console.log(dijkstra); // { a: { distance: 0 }, b: { distance: 1 }, c: { distance: 3 } }
graphlib is a library for creating and manipulating directed graphs in JavaScript. It provides similar functionalities to @dagrejs/graphlib, including adding and removing nodes and edges, graph traversal, and graph algorithms. It is part of the dagre project, which includes tools for graph layout and rendering.
cytoscape is a graph theory library for analysis and visualization. It provides a rich set of features for graph manipulation, layout, and rendering. Compared to @dagrejs/graphlib, cytoscape offers more advanced visualization capabilities and is suitable for creating interactive graph-based applications.
vis-network is a library for creating, manipulating, and visualizing networks. It provides a wide range of features for graph visualization, including different layout algorithms and interaction capabilities. While @dagrejs/graphlib focuses on graph manipulation and algorithms, vis-network emphasizes visualization and user interaction.
English | 中文
Graphlib is a JavaScript library that provides data structures for undirected and directed multi-graphs along with algorithms that can be used with them.
To learn more see our Wiki.
There are 2 versions on NPM, but only the one in the DagreJs org is receiving updates right now.
Graphlib is licensed under the terms of the MIT License. See the LICENSE file for details.
FAQs
A directed and undirected multi-graph library
We found that @dagrejs/graphlib demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.